package com.seeyon.apps.kk.util;

import java.util.Random;

public class RandomCode {

	public static String getStringPwd(int length) {
		String val = "";
		Random random = new Random();
		// length为几位密码
		for (int i = 0; i < length; i++) {
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 输出字母还是数字
			if ("char".equalsIgnoreCase(charOrNum)) {
				// 输出是大写字母还是小写字母
				int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char) (random.nextInt(26) + temp);
			} else if ("num".equalsIgnoreCase(charOrNum)) {
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val;
	}
	
	// 生成用户编号
	public static String userCode() {
		Random random = new Random();
		String result = "";
		for (int i = 0; i < 8; i++) {
			// 首字母不能为0
			result += (random.nextInt(9) + 1);
		}
		return result;
	}
}
